package com.data.collect.logic;


import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;

import org.json.JSONObject;

/**
 * build 数据控制类
 */
public class TelephoneController {

    private static TelephoneController instance;
    TelephonyManager tm ;

    public static TelephoneController getInstance() {
        if (instance == null){
            instance = new TelephoneController();
        }
        return instance;
    }

    private  int itedbm;
    /**
     *初始化
     * @param context
     */
    public void init(Context context){
        tm =(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(new PhoneStateListener(){
            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                super.onSignalStrengthsChanged(signalStrength);

                itedbm = signalStrength.getGsmSignalStrength();

            }
        }, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

    }


    /**
     * 返回电话状态
     * @return
     */
    public int callState(){
        return  tm.getCallState();
    }

    /**
     * 数据活动状态
     * @return
     */
    public int dataActivityState(){
        return  tm.getDataActivity();
    }

    /**
     * 获取数据连接状态
     * @return
     */
    public int dataState(){
        return  tm.getDataState();
    }



    /**
     *返回当前移动终端的唯一标识
     * @return
     */
    public String getDeviceId(){
        return  tm.getDeviceId();
    }




    /**
     *返回移动终端的软件版本
     * @return
     */
    public String getDeviceSoftwareVersion(){
        return  tm.getDeviceSoftwareVersion();
    }


    /**
     *返回移动终端的软件版本
     * @return
     */
    public String getLine1Number(){
        return  tm.getLine1Number();
    }
  /**
     *返回ISO标准的国家码，即国际长途区号
     * @return
     */
    public String getNetworkCountryIso(){
        return  tm.getNetworkCountryIso();
    }
    /**
     *返回MCC+MNC代码 (SIM卡运营商国家代码和运营商网络代码)(IMSI)
     * @return
     */
    public String getNetworkOperator(){
        return  tm.getNetworkOperator();
    }

    /**
     *返回移动网络运营商的名字
     * @return
     */
    public String getNetworkOperatorName(){
        return  tm.getNetworkOperatorName();
    }
    /**
     *获取网络类型
     * @return
     */
    public int getNetworkType(){
        return  tm.getNetworkType();
    }
    /**
     *返回移动终端的类型
     * @return
     */
    public int getPhoneType(){
        return  tm.getPhoneType();
    }

    /**
     *返回SIM卡提供商的国家代码
     * @return
     */
    public String getSimCountryIso(){
        return  tm.getSimCountryIso();
    }

    /**
     *返回SIM卡提供商的国家代码
     * @return
     */
    public String getSimOperator(){
        return  tm.getSimOperator();
    }

    /**
     *返回MCC+MNC代码 (SIM卡运营商国家代码和运营商网络代码)(IMSI)
     * @return
     */
    public String getSimOperatorName(){
        return  tm.getSimOperatorName();
    }
    /**
     *返回SIM卡的序列号(IMEI)
     * @return
     */
    public String getSimSerialNumber(){
        return  tm.getSimSerialNumber();
    }


    /**
     *返回移动终端
     * @return
     */
    public int  getSimState(){
        return  tm.getSimState();
    }


    /**
     *返回用户唯一标识，比如GSM网络的IMSI编号
     * @return
     */
    public String  getSubscriberId(){
        return  tm.getSubscriberId();
    }

    /**
     *获取语音信箱号码关联的字母标识。
     * @return
     */
    public String  getVoiceMailAlphaTag(){
        return  tm.getVoiceMailAlphaTag();
    }
    /**
     *返回语音邮件号码
     * @return
     */
    public String  getVoiceMailNumber(){
        return  tm.getVoiceMailNumber();
    }
    /**
     *返回语音邮件号码
     * @return
     */
    public boolean  hasIccCard(){
        return  tm.hasIccCard();
    }
    /**
     *返回手机是否处于漫游状态
     * @return
     */
    public boolean  isNetworkRoaming(){
        return  tm.isNetworkRoaming();
    }


    public int getPhonePower(){
        return itedbm;
    }


    @Override
    public String toString() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("callState",callState());
            jsonObject.put("dataActivityState",dataActivityState());
            jsonObject.put("dataState",dataState());
            jsonObject.put("getDeviceId",getDeviceId());
            jsonObject.put("getDeviceSoftwareVersion",getDeviceSoftwareVersion());
            jsonObject.put("getLine1Number",getLine1Number());
            jsonObject.put("getNetworkCountryIso",getNetworkCountryIso());
            jsonObject.put("getNetworkOperator",getNetworkOperator());
            jsonObject.put("getNetworkOperatorName",getNetworkOperatorName());
            jsonObject.put("getNetworkType",getNetworkType());
            jsonObject.put("getPhoneType",getPhoneType());
            jsonObject.put("getSimCountryIso",getSimCountryIso());
            jsonObject.put("getPhoneType",getPhoneType());
            jsonObject.put("getSimOperator",getSimOperator());
            jsonObject.put("getSimOperatorName",getSimOperatorName());
            jsonObject.put("getSimSerialNumber",getSimSerialNumber());
            jsonObject.put("getVoiceMailAlphaTag",getVoiceMailAlphaTag());
            jsonObject.put("getSimOperator",getSimOperator());
            jsonObject.put("getVoiceMailNumber",getVoiceMailNumber());
            jsonObject.put("hasIccCard",hasIccCard());
            jsonObject.put("getVoiceMailNumber",getVoiceMailNumber());
            jsonObject.put("getSimOperator",getSimOperator());
            jsonObject.put("isNetworkRoaming",isNetworkRoaming());
            jsonObject.put("getVoiceMailNumber",getVoiceMailNumber());
            jsonObject.put("getSubscriberId",getSubscriberId());
            jsonObject.put("isNetworkRoaming",isNetworkRoaming());
            jsonObject.put("getPhonePower",getPhonePower());
            return jsonObject.toString();
        }catch (Exception e){
        }
        return super.toString();
    }
}
